package com.example.fszq.volleydemo1.adapters;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.fszq.volleydemo1.R;
import com.example.fszq.volleydemo1.utils.ImageFolder;

import java.util.List;

/**
 * Created by fszq on 2016/5/14.
 */
public class FolderSelectAdapter extends ArrayAdapter<ImageFolder> {
    private int resourceId;

    public  FolderSelectAdapter(Context context, int ResourceId,  List<ImageFolder> mDatas) {
        super(context,ResourceId,mDatas);
        this.resourceId = ResourceId;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ImageFolder dList = getItem(position);
        View view;
        ViewHolder viewHolder;

        if (convertView == null) {
            view = LayoutInflater.from(getContext()).inflate(resourceId, null);
            viewHolder = new ViewHolder();
            viewHolder.id_dir_item_name = (TextView) view.findViewById(R.id.id_dir_item_name);
            viewHolder.id_dir_item_count = (TextView)view.findViewById(R.id.id_dir_item_count);
            viewHolder.id_dir_item_image = (ImageView)view.findViewById(R.id.id_dir_item_image);
            view.setTag(viewHolder);
        } else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag(); // 重新获取ViewHolder

        }

        Glide.with(getContext())
                .load(dList.getFirstImagePath())
                .into(viewHolder.id_dir_item_image);

        viewHolder.id_dir_item_name.setText(dList.getName());
        Log.d("picurl", dList.getName());
        viewHolder.id_dir_item_count.setText(dList.getCount()+"张");
        return view;

    }

    class ViewHolder {
        TextView id_dir_item_name,id_dir_item_count;
        ImageView id_dir_item_image;
    }
}
